<?php
/**
 * jishupu-cms
 * @Author:技术铺
 * @Date:2021/11/21
 */

namespace App\Filters;

/**
 * 信息模块过滤器
 *
 * Class InfoFilter
 * @package App\Filters
 */
class InfoFilter extends BaseFilter
{
    /**
     * 关键词组合搜索条件
     * @param $keywords_key
     */
    protected function keywordsKey($keywords_key)
    {
        if (filled($this->filters['keywords_value'])) {
            if (filled($keywords_key)) {
                if ($keywords_key == 'title') {
                    return $this->builder->where('title', 'like', '%' . $this->filters['keywords_value'] . '%');
                } else {
                    return $this->builder->where($keywords_key, 'like', '%' . $this->filters['keywords_value'] . '%');
                }
            } else {
                return $this->builder->where('id', -1);
            }
        }
    }

    /**
     * 状态
     * @param $status
     * @return mixed
     */
    protected function status($status)
    {
        if (filled($status)) {
            return $this->builder->where('status', $status);
        }
    }

    /**
     * 是否置顶
     * @param $top
     * @return mixed
     */
    protected function top($top)
    {
        if (filled($top)) {
            return $this->builder->where('top', $top);
        }
    }


    /**
     * 创建时间范围
     * @param $created_at
     * @return mixed
     */
    protected function createdAt($created_at = [])
    {
        if (!empty($created_at)) {
            return $this->builder->whereBetween('created_at', $created_at);
        }
    }


    /**
     * 推荐类型
     * @param $recommend_type
     * @return mixed
     */
    protected function recommendType($recommend_type = [])
    {
        if (!empty($recommend_type)) {
            return $this->builder->whereRaw('FIND_IN_SET(?,recommend_type)', $recommend_type);
        }
    }

}
